



clear all
set maxvar 17000
graph set window fontface "Times New Roman"
set more off, perm
*cap noisily cd "/Users/dahyeonjeong/Dropbox/MaLT 2017/Data"
cap noisily cd "/Users/aspearot/Dropbox/MaLT 2017/Draft/submission_draft/ReStat/resubmission 2/replication package/malt/"


global model "Model"

#delimit ;

insheet using "Data/buying_inputs_MNL_replication.csv", clear;

count if select==1;


rename dist_km_direct distance_km;
drop if distance_km ==.;

rename dist_km_direct_rural distance_km_rural;
rename dist_km_direct_main distance_km_main;

egen ag = group(ag_village ag_ward);

count if select==1;

gen r0000 = 0;
gen r0001 = 0;
gen r0105 = 0;
gen r0510 = 0;
gen r1015 = 0;
gen r1520 = 0;
gen r2030 = 0;
gen r3040 = 0;
gen r4050 = 0;
gen r50100 = 0;
gen r100more = 0;

replace r0000 = 1 if (distance_km_rural==0);
replace r0001 = 1 if (distance_km_rural>0&distance_km_rural<=1);
replace r0105 = 1 if (distance_km_rural>0&distance_km_rural<=5);
replace r0510 = 1 if (distance_km_rural>5&distance_km_rural<=10);
replace r1015 = 1 if (distance_km_rural>10&distance_km_rural<=15);
replace r1520 = 1 if (distance_km_rural>15&distance_km_rural<=20);
replace r2030 = 1 if (distance_km_rural>20);

gen m0000 = 0;
gen m0001 = 0;
gen m0105 = 0;
gen m0510 = 0;
gen m1015 = 0;
gen m1520 = 0;
gen m2030 = 0;
gen m3040 = 0;
gen m4050 = 0;
gen m50100 = 0;
gen m100more = 0;

replace m0000 = 1 if (distance_km_main==0);
replace m0001 = 1 if (distance_km_main>0&distance_km_main<=1);
replace m0105 = 1 if (distance_km_main>0&distance_km_main<=5);
replace m0510 = 1 if (distance_km_main>5&distance_km_main<=10);
replace m1015 = 1 if (distance_km_main>10&distance_km_main<=15);
replace m1520 = 1 if (distance_km_main>15&distance_km_main<=20);
replace m2030 = 1 if (distance_km_main>20&distance_km_main<=30);
replace m3040 = 1 if (distance_km_main>30&distance_km_main<=40);
replace m4050 = 1 if (distance_km_main>40&distance_km_main<=50);
replace m50100 = 1 if (distance_km_main>50&distance_km_main<=75);
replace m100more = 1 if (distance_km_main>75);

su distance_km if select==1;
su distance_km_main if select==1;
su distance_km_rural if select==1;

egen min_distance_km=min(distance_km), by(id);


asclogit select m0105 m0510 m1015 m1520 m2030 m3040 m4050 m50100 m100more r0105 r0510 r1015 r1520 r2030, case(id) alternatives(ag) diff technique(nr 10 dfp 10) iterate(100);
outreg2 m0105 m0510 m1015 m1520 m2030 m3040 m4050 m50100 m100more r0105 r0510 r1015 r1520 r2030 using "Results/MNL_Replication_Edit.tex", replace;


		mat b =e(b);
		*matrix d_0001 = b[1,1];
		matrix m_0105 = b[1,1];
		matrix m_0510 = b[1,2];
		matrix m_1015 = b[1,3];
		matrix m_1520 = b[1,4];
		matrix m_2030 = b[1,5];
		matrix m_3040 = b[1,6];		
		matrix m_4050 = b[1,7];
		matrix m_50100 = b[1,8];			
		matrix m_100more = b[1,9];		
		*matrix district = b[1,11];	

		matrix r_0105 = b[1,10];
		matrix r_0510 = b[1,11];
		matrix r_1015 = b[1,12];
		matrix r_1520 = b[1,13];
		matrix r_2030 = b[1,14];
		*matrix r_3040 = b[1,15];		
		*matrix r_4050 = b[1,16];
		*matrix r_50100 = b[1,17];				
		
		
matrix tosave = m_0105, m_0510, m_1015, m_1520, m_2030, m_3040, m_4050, m_50100, m_100more, r_0105, r_0510, r_1015, r_1520, r_2030;

matrix colnames tosave = m_0105 m_0510 m_1015 m_1520 m_2030 m_3040 m_4050 m_50100 m_100more r_0105 r_0510 r_1015 r_1520 r_2030;
 
*xsvmat tosave, saving("/Users/aspearot/Dropbox/MaLT 2017/Data/MaLT Project Data/Final Analysis Datasets/buying_fert_MNL_binned_030422.dta", replace) names(col);

svmat tosave;


rename tosave1 m_0105 ;
rename tosave2 m_0510 ;
rename tosave3 m_1015 ;
rename tosave4 m_1520 ;
rename tosave5 m_2030 ;
rename tosave6 m_3040 ;
rename tosave7 m_4050 ;
rename tosave8 m_50100 ;
rename tosave9 m_100more ;
rename tosave10 r_0105 ;
rename tosave11 r_0510 ;
rename tosave12 r_1015 ;
rename tosave13 r_1520 ;
rename tosave14 r_2030 ;

keep m_0105 m_0510 m_1015 m_1520 m_2030 m_3040 m_4050 m_50100 m_100more r_0105 r_0510 r_1015 r_1520 r_2030 ;

drop if m_0105==. ;

save "Data/buying_fert_MNL_binned_replication.dta", replace ;







************************ Distance and Income


clear all
set maxvar 17000
graph set window fontface "Times New Roman"
set more off, perm
*cap noisily cd "/Users/dahyeonjeong/Dropbox/MaLT 2017/Data"
cap noisily cd "/Users/aspearot/Dropbox/MaLT 2017/Draft/submission_draft/ReStat/resubmission 2/replication package/malt/"



global model "Model"

#delimit ;

insheet using "Data/buying_inputs_MNL_replication.csv", clear;

count if select==1;

su;

rename dist_km_direct distance_km;
drop if distance_km ==.;

rename dist_km_direct_rural distance_km_rural;
rename dist_km_direct_main distance_km_main;

gen ln_income = 0;
replace ln_income = 1 if income>0;
*rename google_vil_mkt_km_o origin;
*rename google_vil_mkt_km_d destination;

egen ag = group(ag_village ag_ward);

count if select==1;


gen r0000 = 0;
gen r0001 = 0;
gen r0105 = 0;
gen r0510 = 0;
gen r1015 = 0;
gen r1520 = 0;
gen r2030 = 0;
gen r3040 = 0;
gen r4050 = 0;
gen r50100 = 0;
gen r100more = 0;

replace r0000 = 1 if (distance_km_rural==0);
replace r0001 = 1 if (distance_km_rural>0&distance_km_rural<=1);
replace r0105 = 1 if (distance_km_rural>0&distance_km_rural<=5);
replace r0510 = 1 if (distance_km_rural>5&distance_km_rural<=10);
replace r1015 = 1 if (distance_km_rural>10&distance_km_rural<=15);
replace r1520 = 1 if (distance_km_rural>15&distance_km_rural<=20);
replace r2030 = 1 if (distance_km_rural>20);
*replace r3040 = 1 if (distance_km_rural>30&distance_km_rural<=40);
*replace r4050 = 1 if (distance_km_rural>40&distance_km_rural<=50);
*replace r50100 = 1 if (distance_km_rural>50&distance_km_rural<=100);
*replace r100more = 1 if (distance_km_rural>100);

gen m0000 = 0;
gen m0001 = 0;
gen m0105 = 0;
gen m0510 = 0;
gen m1015 = 0;
gen m1520 = 0;
gen m2030 = 0;
gen m3040 = 0;
gen m4050 = 0;
gen m50100 = 0;
gen m100more = 0;

replace m0000 = 1 if (distance_km_main==0);
replace m0001 = 1 if (distance_km_main>0&distance_km_main<=1);
replace m0105 = 1 if (distance_km_main>0&distance_km_main<=5);
replace m0510 = 1 if (distance_km_main>5&distance_km_main<=10);
replace m1015 = 1 if (distance_km_main>10&distance_km_main<=15);
replace m1520 = 1 if (distance_km_main>15&distance_km_main<=20);
replace m2030 = 1 if (distance_km_main>20&distance_km_main<=30);
replace m3040 = 1 if (distance_km_main>30&distance_km_main<=40);
replace m4050 = 1 if (distance_km_main>40&distance_km_main<=50);
replace m50100 = 1 if (distance_km_main>50&distance_km_main<=75);
replace m100more = 1 if (distance_km_main>75);



gen r0000_ln_income = r0000*ln_income;
gen r0001_ln_income = r0001*ln_income;
gen r0105_ln_income = r0105*ln_income;
gen r0510_ln_income = r0510*ln_income;
gen r1015_ln_income = r1015*ln_income;
gen r1520_ln_income = r1520*ln_income;
gen r2030_ln_income = r2030*ln_income;
gen r3040_ln_income = r3040*ln_income;
gen r4050_ln_income = r4050*ln_income;
gen r50100_ln_income = r50100*ln_income;
gen r100more_ln_income = r100more*ln_income;

gen m0000_ln_income = m0000*ln_income;
gen m0001_ln_income = m0001*ln_income;
gen m0105_ln_income = m0105*ln_income;
gen m0510_ln_income = m0510*ln_income;
gen m1015_ln_income = m1015*ln_income;
gen m1520_ln_income = m1520*ln_income;
gen m2030_ln_income = m2030*ln_income;
gen m3040_ln_income = m3040*ln_income;
gen m4050_ln_income = m4050*ln_income;
gen m50100_ln_income = m50100*ln_income;
gen m100more_ln_income = m100more*ln_income;

*define within ward and within district dummies  61,285;

su distance_km if select==1;
su distance_km_main if select==1;
su distance_km_rural if select==1;

egen min_distance_km=min(distance_km), by(id);


asclogit select m0105 m0510 m1015 m1520 m2030 m3040 m4050 m50100 m100more r0105 r0510 r1015 r1520 r2030 m0105_ln_income m0510_ln_income m1015_ln_income m1520_ln_income m2030_ln_income m3040_ln_income m4050_ln_income m50100_ln_income m100more_ln_income r0105_ln_income r0510_ln_income r1015_ln_income r1520_ln_income r2030_ln_income, case(id) alternatives(ag) diff technique(nr 10 dfp 10) iterate(100);
outreg2 m0105 m0510 m1015 m1520 m2030 m3040 m4050 m50100 m100more r0105 r0510 r1015 r1520 r2030 m0105_ln_income m0510_ln_income m1015_ln_income m1520_ln_income m2030_ln_income m3040_ln_income m4050_ln_income m50100_ln_income m100more_ln_income r0105_ln_income r0510_ln_income r1015_ln_income r1520_ln_income r2030_ln_income using "Results/MNL_Income_Binned.tex", replace;




















